package com.example.tnot.Teacher.CoursePart.CourseInternal.ClassDetail.VpFragment;

import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;

import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.tnot.R;
import com.example.tnot.Teacher.BaseFragment.BaseBackFragment;
import com.example.tnot.Teacher.CoursePart.CourseInternal.ClassDetail.VpFragment.InternalAdapter.rv_classDetail_moreAdapter;
import com.example.tnot.Teacher.CoursePart.CourseInternal.ClassDetail.ItemBean.MoreHome;
import com.example.tnot.Util.popupwindow.FloatWindowService;

import java.util.ArrayList;
import java.util.List;

public class ClassDetailInternalFragment extends BaseBackFragment {
    private static final String ARG_CONTENT = "content";
    View view;
    RecyclerView rv_ClassDetailContent;
    List<MoreHome> list;
    Intent FloatIntent;
    ImageView iv_add;
    BroadcastReceiver floatWindowReceiver;


    public ClassDetailInternalFragment() {
    }

    public static ClassDetailInternalFragment newInstance(String content) {
        ClassDetailInternalFragment fragment = new ClassDetailInternalFragment();
        Bundle args = new Bundle();
        args.putString(ARG_CONTENT, content);
        fragment.setArguments(args);
        return fragment;
    }
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.course_class_detail_internal_fragment, container, false);
        iv_add = view.findViewById(R.id.iv_add);
        String type = getArguments().getString(ARG_CONTENT);
        list = new ArrayList<>();
        rv_ClassDetailContent = view.findViewById(R.id.rv_ClassDetailContent);
        rv_classDetail_moreAdapter adapter = new rv_classDetail_moreAdapter(list);
        rv_ClassDetailContent.setLayoutManager(new LinearLayoutManager(getActivity()));



        if(type !=null){
            switch (type){
                case "任务":
                    if (iv_add.getVisibility()==View.VISIBLE){
                        iv_add.setVisibility(View.GONE);
                    }

                    list.clear();

                    break;
                case "章节":
                    if (iv_add.getVisibility()==View.GONE){
                        iv_add.setVisibility(View.VISIBLE);
                    }
                    list.clear();
                    list.add(new MoreHome(R.drawable.ic_course_cover,"如何学好计算机","qqmao",100,"章节"));
                    list.add(new MoreHome(R.drawable.ic_course_cover,"英语1","qqmao",100,"章节"));
                    list.add(new MoreHome(R.drawable.ic_course_cover,"英语2","qqmao",100,"章节"));
                    // 在需要获取适配器的地方调用
                    adapter = new rv_classDetail_moreAdapter(list);
                    rv_ClassDetailContent.setAdapter(adapter);
                    iv_add.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            NavController navController = Navigation.findNavController(v);
                            navController.navigate(R.id.action_classDetailFragment_to_addChapterFragment);
                        }
                    });



                    break;
                case "更多":
                    if (iv_add.getVisibility()==View.VISIBLE){
                        iv_add.setVisibility(View.GONE);
                    }
                    //静态添加
                    list.clear();
                    list = new ArrayList<>();
                    list.add(new MoreHome("资源","更多"));
                    list.add(new MoreHome("班级成员","更多"));
                    list.add(new MoreHome("班级空间","更多"));
                    list.add(new MoreHome("学习记录","更多"));
                    list.add(new MoreHome("我的评价","更多"));
                    list.add(new MoreHome("成绩查询","更多"));
                    list.add(new MoreHome("我的评论","更多"));
                    adapter = new rv_classDetail_moreAdapter(list);
                    rv_ClassDetailContent.setAdapter(adapter);
                    break;
            }
        }
        return view;
    }
    private void startFloatWindowService() {
        Intent intent = new Intent(getActivity(), FloatWindowService.class);
        getActivity().startService(intent);
    }

    private void stopFloatWindowService() {
        Intent intent = new Intent(getActivity(), FloatWindowService.class);
        getActivity().stopService(intent);
    }

}